<?php

/**
 * Class own_shopControl
 * 自选商品
 */

  Class own_shopControl extends mobileMemberControl{

      /*商品列表*/
      public function goods_listOp(){
          $goods_model = Model('goods');
          if($_GET['gc_id0']){
              $condotion_goods['gc_id'] = $_GET['gc_id0'];
          }
          if($_GET['gc_id1']){
              $condotion_goods['gc_id1'] = $_GET['gc_id1'];
          }
          if($_GET['gc_id2']){
              $condotion_goods['gc_id2'] = $_GET['gc_id2'];
          }
          $condotion_goods['goods_cate'] = array('neq',6);
          $condotion_goods['goods_state']   = 1;
          $condotion_goods['goods_verify']  = 1;
          $page = $_GET['page'];
          $goods_info = $goods_model->getGoodsList($condotion_goods,'','',$page,8);
          // 获取顶级分类
          foreach($goods_info as $k=>$v){
              $goods_info[$k]['imageUrl'] = thumb($v);
          }
          if(!empty($goods_info)) {
              echo json_encode($goods_info);
          }else{
              echo json_encode(0);
          }
      }

      /**
       * 添加自选商品到店铺
       */
      public function addGoodstoStoreOp(){
          $id = $_POST['id'];
          $goods_model= model('goods');
          // 判断商品是否存在
          $goods = $goods_model->getGoodsInfo(array('goods_id'=>$id));
          // 判断本店是否已经自选
          $my_goods = Model('my_store')->where(array('goods_id'=>$id,'store_id'=>$_SESSION['store_id']))->select();
          if($goods && empty($my_goods)){
              $data['goods_id'] = $id;
              $data['store_id'] = $_SESSION['store_id'];
              $res = Model('my_store')->insert($data);
              if($res){
                     $array = array(
                         'code'=>200,
                         "msg" => "添加成功",
                     );
              }else{
                     $array = array(
                      'code'=>400,
                      "msg" => "添加失败,请稍后再试……",
                     );
              }
          }else{
              $array = array(
                  'code'=>401,
                  "msg" => "已经添加或商品不存在",
              );
          }
          echo json_encode($array);
      }
  }
?>